<@master template="master/master-loan" title="新增客户推荐信息">
<@css href="/easyui/themes/default/easyui.css"/>
<@css href="/easyui/themes/icon.css"/>
<@js src="/easyui/jquery.easyui.min.js"/><@jsRender/>

<div class="detailsBox">

		<form class="action-ajax-form" id="save_form" action="/rrecommend/saveO2oRecommend"
			method="post">
			<div class="openBox">
				<h3 class="mt20">
					<i class="jtIco"></i>客户推荐信息
				</h3>
				<div class="detaiTab">
					<table cellspacing="0" cellpadding="0" border="0" width="100%">
						<tbody>
						<tr>
							 	<td class="bg" align="right" width="15%">当前申请人为:</td>
				                <td colspan="3">
				                    <@select 
									dataSouceType="RECOMMENDSQ_TYPE" name="sqType" id='sqType'
									value="${o2oRecommendEntity.sqType}"
									/>
									<input size=30  type="hidden" name="id" id="id" 
				                    	value="${o2oRecommendEntity.id}"
				                    />
				                    <input size=30  type="hidden" name="type" id="type" 
				                    	value=""
				                    />
									  <span><font color="red">*</font></span>
				                </td>
						</tr>
							<tr>
								<td width="15%" align="right" class="bg">客户姓名：</td>
								<td width="35%">
								  <input  type="text" name="userName" id="userName" 
				                    	value="${o2oRecommendEntity.userName}"
				                    />
								 <span
									style="color: red;">*</span>
								</td>
								
								 <td class="bg" align="right" width="15%">证件号码:</td>
				                <td>
				                    <input size=30  type="text" name="documentNo" id="documentNo" 
				                    	value="${o2oRecommendEntity.documentNo}"
				                    />
									  <span><font color="red">*</font></span>
				                </td>
							</tr>
							
							<tr>
								<td width="15%" align="right" class="bg">经办人：</td>
								<td>
								<@autocomplete url="/loanrest/likeOperator?name="
									name="operatorName"
									id="operatorName"
									onclick="_onchange_hidden_input('operatorNo');"
									value="${o2oRecommendEntity.operatorName}"
									hideIdName="operatorNo"
									hideIdValue="${o2oRecommendEntity.operatorNo}"/>(联想)<span
									style="color: red;">*</span><span id="operatorNoErorr"
									style="color: red;"></span>
								</td>
								<td width="15%" align="right" class="bg">经办省区：</td>
								<td>
										<select name="operatorProvinceId" id="operatorProvinceId">
							        		<option  value="">请选择
							        		<#list ActOrgEntitys as ActOrgEntity>
							        			<option value="${ActOrgEntity.orgId}" <#if ActOrgEntity.orgId == o2oRecommendEntity.operatorProvinceId>selected="selected" </#if>>${ActOrgEntity.orgName}
							        		</#list>
							        	</select>
									<span style="color: red;">*</span>
								</td>
							</tr>
							<tr>
								<td width="15%" align="right" class="bg">推荐人：</td>
								<td>
								<@autocomplete url="/loanrest/likeOperator?name="
									name="referrerName"
									id='referrerName'
									onclick="_onchange_hidden_input('referrerName');"
									value="${o2oRecommendEntity.referrerName}"
									hideIdName="referrerNo"
									hideIdValue="${o2oRecommendEntity.referrerNo}"/>(联想)<span
									style="color: red;">*</span><span id="operatorNoErorr"
									style="color: red;"></span>
								</td>
								<td width="15%" align="right" class="bg">推荐省区：</td>
								<td>
										<select name="referrerProvinceId" id="referrerProvinceId">
							        		<option  value="">请选择
							        		<#list ActOrgEntitys as ActOrgEntity>
							        			<option value="${ActOrgEntity.orgId}" <#if ActOrgEntity.orgId == o2oRecommendEntity.referrerProvinceId>selected="selected" </#if>>${ActOrgEntity.orgName}
							        		</#list>
							        	</select>
									<span style="color: red;">*</span>
								</td>
							</tr>
							
							<tr>
								<td width="15%" align="right" class="bg">客户联系方式：</td>
								<td>
								 <input size=20  type="text" name="userPhone" id="userPhone" 
								 value="${o2oRecommendEntity.userPhone}" />
								<span
									style="color: red;">*</span>
								</td>
								<td width="15%" align="right" class="bg" title="合作方推荐(类型一) ：品牌推荐人与经办人的利益划分按1:9计算。 批量客户推荐(类型二)品牌推荐人与经办人的利益划分按2:8计算 。意向客户推荐(类型三) ：品牌推荐人与经办人的利益划分按3:7计算。详细说明请查看总部发文《渠道共享收益分配试行办法》。 总部推荐（总对总渠道共享业务，共享收益分配比例3:7。）">推荐类型<span class=" wenhaoIco"></span>:</span></td>
				                <td >
				                       <@select dataSouceType="recommendType" name="recommendType"  value="${o2oRecommendEntity.recommendType}"  />
				                </td>
							</tr>
							<!--
							<tr>
								<td width="15%" align="right" class="bg">所属渠道：</td>
								<td>
								 <@autocomplete url="/rpartner/referrer?loanType=${loanApplyFileEntity.loanType}&partnerName="
									name="partnerName" value="${o2oRecommendEntity.partnerName}" hideIdName="partnerId"
									hideIdValue="${o2oRecommendEntity.partnerId}"/>(联想)
								<span
									style="color: red;">*</span>
								</td>
								
								<td width="15%" align="right" class="bg" >所属品牌<span class=" wenhaoIco"></span>:</span></td>
				                <td >
				                       <@autocomplete url="/rbrand/search?keywords=" name="xbrandId" class="tabInp action-valid-field"
										hideIdName="brandId" hideIdValue="${vo.id}" id="brandId" value="${vo.brandName }"/>(联想)
									<span	style="color: red;">*</span>
				                </td>
				                 
							</tr>
							-->
						</tbody>
					</table>
				</div>
			</div>
			<div class=" mtb20 tac">
			
			
			<@permission permissionName="saveRecommend"> 
				<input type="button" onclick="search()" class="btn_auto_30 btn_blue" value="保 存">
			</@permission>
			<@permission permissionName="saveRecommendAndStart"> 
				<input type="button" onclick="saveAndStartNew()" value="保存并启动流程" class="btn_auto_30 btn_blue" />
			</@permission>
				<a class="btn_auto_30 btn_blue ml20"
					href="javascript:history.back();">返回</a>&nbsp;
			</div>
		</form>
</div>
<script type="text/javascript">

		$(function () { 
					var ss = $("#sqType").children('option:selected').val(); 
					if(ss=='O'){
						$('#operatorName').attr("readonly","readonly");
						$('#operatorProvinceId').attr("disabled","disabled");
					}else if(ss=='R'){
						$('#referrerName').attr("readonly","readonly");
						$('#referrerProvinceId').attr("disabled","disabled");
					}
		});

  function saveAndStartNew(){
		$("#save_form").action = "/rrecommend/saveO2oRecommend";
		$("#type").val('2');
		 if($.trim($('#documentNo').val()).length == 0) { 
			   $.actionDialog({message: "身份证号码没有输入"});
			   $('#documentNo').focus();
			 	 return  ;
			} else {
				  if(IdentityCodeValid($.trim($('#documentNo').val())) == false) {
					  $.actionDialog({message: "身份证号码格式不正确"});
					   $('#documentNo').focus();
					   return  ;
				   }
			}
		$("#save_form").submit();
	}
	
	
	function search(){
          var documentNo= $("#documentNo").val();
          $("#type").val('1');
            // 验证身份证
		 if($.trim($('#documentNo').val()).length == 0) { 
			   $.actionDialog({message: "身份证号码没有输入"});
			   $('#documentNo').focus();
			 	 return  ;
			} else {
				  if(IdentityCodeValid($.trim($('#documentNo').val())) == false) {
				  $.actionDialog({message: "身份证号码格式不正确"});
				   $('#documentNo').focus();
				   return  ;
				}
			}
		  
		   $("#save_form").submit();
		   
         }
	
	// 验证身份证 
		function IdentityCodeValid(code) { 
            var city={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江 ",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北 ",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏 ",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外 "};
            var tip = "";
            var pass= true;
		 var pattern = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/; 
           if (!pattern.test(code)) {
               tip = "身份证号格式错误";
               pass = false;
               }                                                         
            
           else if(!city[code.substr(0,2)]){
                tip = "地址编码错误";
                pass = false;
            }
            else{
                //18位身份证需要验证最后一位校验位
                if(code.length == 18){
                    code = code.split('');
                    //∑(ai×Wi)(mod 11)
                    //加权因子
                    var factor = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ];
                    //校验位
                    var parity = [ 1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2 ];
                    var sum = 0;
                    var ai = 0;
                    var wi = 0;
                    for (var i = 0; i < 17; i++)
                    {
                        ai = code[i];
                        wi = factor[i];
                        sum += ai * wi;
                    }
                    var last = parity[sum % 11];
                    if(parity[sum % 11] != code[17]){
                        tip = "校验位错误";
                        pass =false;
                    }
                }
            }
            return pass;
        }
	
	
	$("#sqType").change(function () {  
	            var ss = $(this).children('option:selected').val();  
	            $.ajax({
			type: "GET",
			url:"/rrecommend/userdate",
			dataType:"json",
			success:function(result){
			
				if(ss=='R'){
					$("#operatorName").val('');
					$("#operatorName").attr("value",'');
					$("#operatorName").attr("hideidvalue",'');
					$('#operatorName').removeAttr("readonly","readonly");
					$('#operatorNo').removeAttr("readonly","readonly");
					$("#operatorProvinceId").find("option[value = '"+result.org+"']").removeAttr("selected","selected");
					$("#operatorProvinceId").find("option[value = '']").attr("selected","selected");
					$('#operatorProvinceId').removeAttr("disabled","disabled");
					//alert(result.org);
					$("#referrerName").val(result.cname);
					$("#referrerName").attr("value",result.cname);
					$("#referrerName").attr("hideidvalue",result.no);
					$('#referrerName').attr("readonly","readonly");
					$("#referrerProvinceId").find("option[value = '']").removeAttr("selected","selected");
					$("#referrerProvinceId").find("option[value = '"+result.org+"']").attr("selected","selected");
					$('#referrerProvinceId').attr("disabled","disabled");
				}else if(ss=='O'){
					$("#referrerName").val('');
					$("#referrerName").attr("value",'');
					$("#referrerName").attr("hideidvalue",'');
					$('#referrerName').removeAttr("readonly","readonly");
					$("#referrerProvinceId").find("option[value = '"+result.org+"']").removeAttr("selected","selected");
					$("#referrerProvinceId").find("option[value = '']").attr("selected","selected");
					$('#referrerProvinceId').removeAttr("disabled","disabled");
					//alert(result.org);
					$("#operatorName").val(result.cname);
					$("#operatorName").attr("value",result.cname);
					$("#operatorName").attr("hideidvalue",result.no);
					$('#operatorName').attr("readonly","readonly");
					$("#operatorProvinceId").find("option[value = '']").removeAttr("selected","selected");
					$("#operatorProvinceId").find("option[value = '"+result.org+"']").attr("selected","selected");
					$('#operatorProvinceId').attr("disabled","disabled");
				}
		 	}
	 	});
	  });  
</script>
</@master>
